package com.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import javax.swing.JTextField;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.text.NumberFormat;
import java.util.Locale;

import javax.swing.JTextField;
/**
 * 常用的工具类。
 * @author 施俊
 * @since 2004-10-19
 * @version 1.0
 * @see
 */
public class CommonTools {	
	public static boolean isDate(String str){
		boolean breturn=false;
		if(!CommonTools.isNullString(str)){
			try{
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");     
				dateFormat.setLenient(false);     
				dateFormat.parse(str);     
				breturn = true;     
			}catch (Exception e) {   
				breturn = false;
			} 
		}
		return  breturn;
	}
	
	
	public static boolean isLastLine(String[] line){
		boolean breturn=true;
		for(int i=0;i<line.length;i++){
			if("*****".equals(line[i]) || CommonTools.isNullString(line[i])){
				continue;
			}else{
				breturn=false;
				break;
			}
		}		
		return  breturn;
	}	
	
	/**
	 * 判断输入的字符串是否为null，如果是null则返回"",否则，返回原字符串。
	 * @param str
	 * @return
	 */
	public static String null2String(String str)
	{
		if (isNullString(str))
		{
			return "";
		}
		else
			return str.trim();
	}
	
	public static String formatStrDate(String date){
	    
	    String returnFormatDate = "";
	    if(date.length()>1){
	        returnFormatDate = "to_date('"+date+"','yyyy-mm-dd')";
	    }else{
	        returnFormatDate = "null";
	    }
	    return returnFormatDate;
	}
	
	/**
	 * 将字符串转化为日期格式，字符串的格式为：yyyy-mm-dd，<br>
	 * @param date date的格式为：yyyy-mm-dd
	 * @return Date - 如果无法转换，则返回null
	 *
	 */
	public static Date str2Date(String date)
	{		
		java.sql.Date return_Date = null;
		try
		{
			return_Date = java.sql.Date.valueOf(date);
		}
		catch(Exception e)
		{
			return null;
		}
		
		return return_Date;
	}
	
	/**
	 * 将日期转化为字符格式，字符串的格式为：yyyy-mm-dd
	 * @param date 要转化的date
	 * @return String 返回的格式为：yyyy-mm-dd
	 *
	 */
	public static String date2String(Date date){	
		if (date == null){
			return "";
		}else{
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
			return dateFormat.format(date);
		}
	}
	
	/**
	 * 将日期转化为字符格式，字符串的格式为：yyyy-mm-dd
	 * @param date 要转化的date
	 * @return String 返回的格式为：yyyy-mm-dd
	 *
	 */
	public static String time2String(Date date){	
		if (date == null){
			return "";
		}else{
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			return dateFormat.format(date);
		}
	}
	
	public static String time2String2(Date date){	
		if (date == null){
			return "";
		}else{
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			return dateFormat.format(date);
		}
	}
	
	/**
	 * 将日期转化为只有年度的字符格式，字符串的格式为：yyyy
	 * @param date
	 * @return
	 */
	public static String date2Year(Date date)
	{
		if (date == null){
			return "";
		}else{
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
			return sdf.format(date);
		}
	}
	
	/**
	 * 将日期转化为只有年度的字符格式，字符串的格式为：yyyy
	 * @param date
	 * @return
	 */
	public static String date2Month(Date date)
	{
		if (date == null){
			return "";
		}else{
			SimpleDateFormat sdf = new SimpleDateFormat("MM");
			return sdf.format(date);
		}
	}	
	
	public static java.sql.Date util2Sql(java.util.Date date)
	{
		return new java.sql.Date(date.getTime());
	}
    /**
     * 将文件流存储到指定路径
     * 
     * @param stream - 文件流
     * @param filePath - 文件所要存储到的路径
     * @param fileName - 文件名
     * @throws FileNotFoundException
     * @throws IOException
     */
    public static String saveFile(InputStream stream, String filePath, String fileName) 
            throws FileNotFoundException, IOException 
    {
        if(!FileOperator.isFileExist(filePath))
        	FileOperator.createFolder(filePath);
        // 完全路径
        String path = filePath  + File.separator + fileName;
        System.out.println("file save path is：" + path);
        OutputStream bos = new FileOutputStream(path);
        
        int bytesRead = 0;
        byte[] buffer = new byte[8192];
        while ( (bytesRead = stream.read(buffer, 0, 8192)) != -1) {
            bos.write(buffer, 0, bytesRead);//将文件写入服务器
        }
        bos.close();
        stream.close();
        return path;
    }
    
	/**
	 * 删除文件夹，当该文件夹下有文件或者文件夹的时候不能删除该文件夹
	 * @param path
	 * @return boolean
	 *
	 */
	public static boolean deleteFile(String path)
	{
	    System.out.println("delete file：" + path);
		File file = new File(path);
		boolean returnBoolean = file.delete();
		System.out.println("delete:" + returnBoolean);
		return returnBoolean;
	}
	
	/**
	 * 在字符串上加CDATA。
	 * @param string
	 * @return String
	 *
	 */
	public static String addCDATA(String string)
	{
		String returnStr = "<![CDATA[";
		returnStr += string;
		returnStr += "]]>";
		return returnStr;
	}
    
	/**
	 * 判断输入框中的内容是否为空
	 * @param textField - 输入框
	 * @return - true 表示是空，否则，表示不为空
	 */
	public static boolean isInputNull(JTextField textField)
	{
	    if(textField.getText().equals(""))
	    {
	        return true;
	    }
	    return false;
	}
	
	/**
	 * 将char的高四位去掉，再合并成字符串。<br>
	 * 目的是要解决度dbf文件的字段名时，中文出现乱码问题
	 * @param str
	 * @return
	 */
    public static String getStrByCharToByte(String str)
    {
        byte[] temp = new byte[str.length()];
        for(int i = 0; i < str.length(); i ++)
        {
            temp[i] = (byte)(str.charAt(i));
        }
        return new String(temp);
    }
    
    public static boolean isNullString(String str)
    {
    	if(str==null || str.trim().equals("") || str.trim().equalsIgnoreCase("NULL"))
    		return true;
    	else
    		return false;
    }
    public static String convertorQuote(String sqlStr)
    {
    	if (isNullString(sqlStr))
			return "";
    	
		return sqlStr.replaceAll("'","''");
    }
    public List compareList(List list1,List list2){
		List list = new ArrayList();
		if(!list2.equals(list1)){
			for(int i = 0;i < list2.size();i ++){
				if(!list1.contains(list2.get(i)))
					list.add(list2.get(i));
			}
		}
		
		return list;
	}
    public static String toChinese(String strvalue){
	    try{
		    if(strvalue==null)
		    	return null;
		    else{
			    strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
			    return strvalue;
		    }
	    }catch(Exception e){
		    return null;
		}
    } 

    public static String gBK2ISO_8859_1(String str){
    	try {
			return new String(str.getBytes("GBK"),"ISO-8859-1");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return str;
		}
    }
    
    public static String iSO_8859_12GBK(String str){
    	try {
			return new String(str.getBytes("ISO-8859-1"),"GBK");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return str;
		}
    }
    /** 将数组转换成字串 ","分隔*/
    public static String array2String(Object [] array){
    	StringBuffer str = new StringBuffer();
    	for(int i = 0;i < array.length;i ++)
    		str.append((String)array[i]).append(",");
    	if(str.length() != 0)
    		str = new StringBuffer(str.substring(0,str.length() - 1));
    	return str.toString();
    }
    /**
     * 月份判断
     * @param month
     * @return
     */
    public static String monthValidate(int month){
    	String str = "";
    	switch(month){
    	case 1:case 3:case 5:case 7:case 8:case 10:case 12:str = "l";break;
    	case 4:case 6:case 9:case 11:str = "s";break;
    	case 2:str = "m";break;
    	default:str = "err";
    	}
    	return str;
    }
    
    public static void println(Object obj){
    	System.out.println("[ CommonTools DEBUG : ]"+obj);
    }
    /**
     * 将字符串转换为UTF8编码。
     * @param str 未经过编码的字符串。
     * @return UTF8编码的字符串。
     */
    public static String toUtf8String(String str){
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<str.length();i++){
		    char c = str.charAt(i);
		    if (c >= 0 && c <= 255) {
		    	sb.append(c);
		    } 
		    else{
				byte[] b;
				try{
				    b = Character.toString(c).getBytes("utf-8");
				} 
				catch (Exception ex){
				    System.out.println(ex);
				    b = new byte[0];
				}
				for (int j = 0; j < b.length; j++){
				    int k = b[j];
				    if (k < 0) k += 256;
				    sb.append("%" + Integer.toHexString(k).toUpperCase());
				}
		    }
		}
		return sb.toString();
    }
    
	public static String list2String(List list,String st) {
		String str = "";
		for(int i=0;i<list.size();i++){
			if(i==list.size()-1){
				str = str+(String)((HashMap)list.get(i)).get(st);
			}
			else {
				str = str + (String)((HashMap)list.get(i)).get(st)+",";
			}
		}
		return str;
	}
	
	public static String getCurrentYearAndMonth(){
		GregorianCalendar lgc = new GregorianCalendar();
		int year = lgc.get(Calendar.YEAR);
		int month = lgc.get(Calendar.MONTH);
		if(month == 0){
			year = year - 1; 
			month = 12;
		}
		if(month < 10){
			return String.valueOf(year) + "-0" + String.valueOf(month);
		}else{
			return String.valueOf(year) + "-" + String.valueOf(month);
		}
	}
	
    /**
     * 计算年度列表
     * @param span 跨度：当前系统年度的前后跨度
     * @return
     */
	public static List getYear(int span){
		GregorianCalendar lgc = new GregorianCalendar();
        String year = String.valueOf(lgc.get(Calendar.YEAR));
        List list = new ArrayList();
        Map map = null;
        for(int i = Integer.parseInt(year) - span; i <= Integer.parseInt(year) + span;i ++){
        	map = new HashMap();
        	map.put("value",String.valueOf(i));
        	list.add(map);
        }
        return list;
	}
	
	/**
     * 计算年度列表
     * @param span 跨度：当前系统年度的前后跨度
     * @param flag 标识 0：系统时间前 1：系统时间后 其他：系统时间前后
     * @return
     */
	public static List getYears(int span,int flag){
		GregorianCalendar lgc = new GregorianCalendar();
        String year = String.valueOf(lgc.get(Calendar.YEAR));
        List list = new ArrayList();
        Map map = null;
        if(flag == 0)
	        for(int i = Integer.parseInt(year) - span; i <= Integer.parseInt(year);i ++){
	        	map = new HashMap();
	        	map.put("value",String.valueOf(i));
	        	list.add(map);
	        }
        else if(flag == 1)
        	for(int i = Integer.parseInt(year); i <= Integer.parseInt(year) + span;i ++){
	        	map = new HashMap();
	        	map.put("value",String.valueOf(i));
	        	list.add(map);
	        }
        else
        	for(int i = Integer.parseInt(year) - span; i <= Integer.parseInt(year) + span;i ++){
	        	map = new HashMap();
	        	map.put("value",String.valueOf(i));
	        	list.add(map);
	        }
        return list;
	}
	
    /**
     * 为编号左填充指定字符
     * @param src 源字符
     * @param cha 填充字符
     * @param len 填充需要达到的长度
     * @return String 填充后的
     */
	public static String supplyChar(String src,String cha, int len) {
	    String strSrc = src;
		while (strSrc.length() < len) {
			strSrc = cha + strSrc;
		}
		return strSrc;
	}
	
	/**
     * 系统日期取得.  <BR>
     *
     * @author  李晓强
     * @return  yyyymmdd格式
     * @see
     * @since   1.0
     *
     */
    public static String getSysdate() {
        GregorianCalendar lgc = new GregorianCalendar();
        String year = String.valueOf(lgc.get(Calendar.YEAR));
        String month = String.valueOf(lgc.get(Calendar.MONTH) + 1);
        if (month.length() == 1)  month = "0" + month;
        String date = String.valueOf(lgc.get(Calendar.DATE));
        if (date.length() == 1) date = "0" + date;
        return year+ "-" + month + "-" + date;
    }

    /**
     * 系统时间取得.  <BR>
     *
     * @author  李晓强
     * @return  HHMISS
     * @see
     * @since   1.0
     *
     */
    public static String getSystime() {
        GregorianCalendar lgc = new GregorianCalendar();
        String hour = String.valueOf(lgc.get(Calendar.HOUR_OF_DAY));
        if (hour.length() == 1) hour = "0" + hour;
        String minute = String.valueOf(lgc.get(Calendar.MINUTE));
        if (minute.length() == 1) minute = "0" + minute;
        String second = String.valueOf(lgc.get(Calendar.SECOND));
        if (second.length() == 1) second = "0" + second;
        return hour + ":" + minute + ":" + second;
    }
    
    
    
    public static void Debug(Object obj)
    {
    	System.out.println(obj.toString());
    }
    
    public static String FormatDate(java.util.Date date)
    {
    	SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		return format.format(date);    	
    }
    
    public static String FormatDate(java.util.Date date,String format)
    {
    	SimpleDateFormat simpledateformat=new SimpleDateFormat(format);
		return simpledateformat.format(date);    	
    }
    
    public static String formatStrDate2(String date){
	    
	    String returnFormatDate = "";
	    if(date.length()>1){
	        returnFormatDate = "to_date('"+date+"','yyyy-mm-dd')";
	    }else{
	        returnFormatDate = "";
	    }
	    return returnFormatDate;
	}
    
    /**
	 * 将字符串数组转化为整数进行相加，然后将结果作为字符串返回
	 * 
	 * @param String[]
	 *            字符串数组
	 * @return String 字符串数组之和
	 */
	public static String StringArray2String(Object[] stringArray) {
		long sum = 0;
		for (int i = 0; i < stringArray.length; i++) {
			try {
				sum += Long.parseLong((String)stringArray[i]);
			}catch(Exception e){
				sum += 0;
			}
			
		}
		return String.valueOf(sum);
	}

	/**
	 * 将字符串转化为整数进行拆分，拆分为2的n次幂的字符串数组
	 * 
	 * @param String
	 *            字符串数组之和
	 * @return String[] 字符串数组
	 */
	public static String[] String2StringArray(String string) {
		StringBuffer buf = new StringBuffer();
		String binaryString = Long.toBinaryString(Long.parseLong(string));//转为2进制
		//System.out.println(binaryString);
		for (int i = 0; i < binaryString.length(); i++) {
			if (binaryString.charAt(i) == '1') {
				buf.append(String.valueOf((long) Math.pow((double) 2, (double) binaryString.length()-1-i)));
			}
			if(i!=binaryString.length()-1){
				buf.append(", ");
			}
		}
		
		StringTokenizer st = new StringTokenizer(buf.toString(), ", ");
		
		int count=st.countTokens();
		String[] s = new String[count];//判断数组个数
		for (int i = 0; i <count ; i++) {
			s[i] = st.nextToken();
			
		}

		return s;
	}
	
	/**
	 * 将字符串转化为整数进行拆分，拆分为2的n次幂的字符串，中间用逗号分隔
	 * 
	 * @param String
	 *            字符串数组之和
	 * @return String 用逗号分隔的拆分后的字符串
	 */
	public static String String2StringList(String string) {
		StringBuffer buf = new StringBuffer();
		String binaryString = Long.toBinaryString(Long.parseLong(string));//转为2进制
		//System.out.println(binaryString);
		for (int i = 0; i < binaryString.length(); i++) {
			if (binaryString.charAt(i) == '1') {
				buf.append(
						String.valueOf((long) Math.pow((double) 2, (double) binaryString.length()-1-i)));
			}
			if(i!=binaryString.length()-1){
				buf.append(",");
			}
		}
		return buf.toString();
	}

	public static String uniteString(String str1,String str2){
		if(CommonTools.isNullString(str1))
			str1 = "0";
		if(CommonTools.isNullString(str2))
			str2 = "0";
		Set set = new HashSet();
		String [] tmp = String2StringArray(str1);
		for(int i = 0;i < tmp.length;i ++){
			set.add((String)tmp[i]);
		}
		tmp = String2StringArray(str2);
		for(int i = 0;i < tmp.length;i ++){
			set.add((String)tmp[i]);
		}
		return StringArray2String(set.toArray());
	}
    
	public static String [] split(String str){
		return str.split(",");
	}
	
	/**
	 * 将Map按照key值进行排序，key只能是数字，不支持字符
	 * @param Map
	 * @return Map.Entry[] 
	 */
	public static Map.Entry[] getSortedHashtableByKey(Map map) {
	   Set set = map.entrySet();
	   Map.Entry[] entries = (Map.Entry[]) set.toArray(new Map.Entry[set.size()]);
	   Arrays.sort(entries, new Comparator() {
		   public int compare(Object arg0, Object arg1) {
			   String key1 = (String)((Map.Entry) arg0).getKey();
			   String key2 = (String)((Map.Entry) arg1).getKey();
			   return Long.parseLong(key1) > Long.parseLong(key2) ? 1 : -1; 
			  //return ((Comparable) Long.parseLong(key1)).compareTo(Long.parseLong(key2));
		   }
	   });
	   return entries;
	}

	public static boolean isInt(String character) {
		char chars[] = character.toCharArray();
		for (int i = 0; i < chars.length; i++) {
			int ascii = getAscii(chars[i]);
			if (ascii >= 48 && ascii <= 57)
				return true;
		}

		return false;
	}

	public static int getAscii(char cn) {
		byte bytes[] = String.valueOf(cn).getBytes();
		if (bytes.length == 1)
			return bytes[0];
		if (bytes.length == 2) {
			int hightByte = 256 + bytes[0];
			int lowByte = 256 + bytes[1];
			int ascii = (256 * hightByte + lowByte) - 0x10000;
			return ascii;
		} else {
			return 0;
		}
	}

	/**
	 * @字符串加
	 * */
	public static String getSubContent(String str, int length) {
		str = null2String(str);
		if (!("".equals(str) || str.length() < length)) {
			str = str.substring(0, length) + "....";
		}
		return str;
	}

	/**
	 *@判断是否是数字(不包括负数)

	 */
	public static boolean isNumber(String str) {
		String number = "0123456789.";
		if (!"".equals(null2String(str))) {
			char[] chars = str.toCharArray();
			for (int i = 0; i < chars.length; i++) {
				if (number.indexOf(String.valueOf(chars[i]), 0) == -1) {
					return false;
				}
			}
		} else {
			return false;
		}
		return true;
	}
	
	/**
	 *@判断是否是数字(包括负数)

	 */
	public static boolean isNumber1(String str) {
		String number = "0123456789.-";
		if (!"".equals(null2String(str))) {
			char[] chars = str.toCharArray();
			for (int i = 0; i < chars.length; i++) {
				if (number.indexOf(String.valueOf(chars[i]), 0) == -1) {
					return false;
				}
			}
		} else {
			return false;
		}
		return true;
	}

	/**
	 * UTF-8����ת����
	 * 
	 * @param s
	 * @return
	 */
	public static String utf8ToStr(String s) {
		String ret = "null";
		try {
			ret = java.net.URLDecoder.decode(s, "utf-8");
		} catch (UnsupportedEncodingException ex) {
		}
		return ret;
	}

	/**
	 * @author wangk071226
	 * @list转化JSON格式��LIST
	 */
	public static String ListFormatJSON(List list) {
		StringBuffer sb = new StringBuffer();
		if (list != null && list.size() > 0) {
			Map map = new HashMap();
			sb.append("{success:true,data:{list:[");
			for (int i = 0; i < list.size(); i++) {
				map = (Map) list.get(i);
				sb.append("['");
				sb.append((String) map.get("CODE"));
				sb.append("','");
				sb.append((String) map.get("NAME"));
				if (i == list.size() - 1) {
					sb.append("']");
				} else {
					sb.append("'],");
				}
			}
			sb.append("]}}");
		} else {
			sb.append(" {success:true,data:{list:[['','']]}}");
		}
		System.out.println(sb.toString());
		return sb.toString();
	}
	/**
	 * @author leip
	 * @list转化JSON格式��LIST
	 */
	public static String ListOneFormatJSON(List list,String[] columns) {
		StringBuffer sb = new StringBuffer();
		if (list != null && list.size() ==1) {
			Map map = new HashMap();
			sb.append("{success:true,data:{list:[['status','1'],");
			for (int i = 0; i < columns.length; i++) {
				map = (Map) list.get(0);
				sb.append("['");
				sb.append(columns[i]);
				sb.append("','");
				sb.append((String) map.get(columns[i]));
				if (i == columns.length - 1) {
					sb.append("']");
				} else {
					sb.append("'],");
				}
			}
			sb.append("]}}");
		}   else {
			sb.append(" {success:true,data:{list:[['status','0']]}}");
		}
		System.out.println(sb.toString());
		return sb.toString();
	}
	/**
	 * ISO8859_1转GBK
	 * 
	 * @return GBK
	 */

	public static String ISO8859_1ChangeGBK(String strvalue) {
		try {
			if (strvalue == null)
				return null;
			else {
				strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
				return strvalue;
			}
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * ISO-8859-1转GBK
	 * 
	 * @return GBK
	 */

	public static String iSO_8859_12ChangeGBK(String str) {
		try {
			if (str == null)
				return null;
			else {
				return new String(str.getBytes("ISO-8859-1"), "GBK");
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return str;
		}

	}
	/**
	 * UTF8转GBK
	 * 
	 * @return GBK
	 */

	public static String UTF8Changegb2312(String strvalue) {
		try {
			if (strvalue == null)
				return null;
			else {
				strvalue = new String(strvalue.getBytes("UTF8"), "GBK");
				return strvalue;
			}
		} catch (Exception e) {
			return null;
		}
	}

	/** ȡ�õ�ǰ��� 
	 * @取得当前系统年份
	 * */
	public static String getDateYear() {
		String year = "";
		java.text.SimpleDateFormat time = new java.text.SimpleDateFormat("yyyy");
		year = time.format(new java.util.Date());

		return year;
	}
	/** ȡ�õ�ǰ��� 
	 * @取得当前系统月份
	 * */
	public static String getDateMonth() {
		String year = "";
		java.text.SimpleDateFormat time = new java.text.SimpleDateFormat("MM");
		year = time.format(new java.util.Date());

		return year;
	}
	/** ȡ�õ�ǰ��� 
	 * @取得系统时间
	 * */
    public static String getDateTime()
    {
        java.text.SimpleDateFormat f = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = f.format(new java.util.Date());
        return time;
    }	/** ȡ�õ�ǰ��� 
	 * @取得系统时间
	 * */
    public static String getDateTime2()
    {
        java.text.SimpleDateFormat f = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
        String time = f.format(new java.util.Date());
        return time;
    }
	/** ȡ�õ�ǰ��� 
	 * @格式化系统时间（年月日）
	 * */
    public static String getDateTime(Date date)
    {
    	if(!"".equals(date)){
        java.text.SimpleDateFormat f = new java.text.SimpleDateFormat("yyyy-MM-dd");
        String time = f.format(date);
        return time;
    	}
		return null;
    }
	/**
	 * @判断list是否为空
	 * @如果为空map("CODE","");map("NAME","");
	 * */
	public static List chack_list(List list){
		if(list!=null&&list.size()>0){
			return list;
		}else{
			Map map = new HashMap();
			map.put("CODE","");
			map.put("NAME","");
			list.add(map);
		return list;
		}
	}
	/**
	 * @String 类型转化为 int
	 * */
	public static int getIntNull(String str){
	    if (str != null && !str.equals("")){
	        return Integer.parseInt(str);
	    }else{
	      return 0;
	    }
	  }
	/**
	 * @String 去除字符串的前后空格
	 * */
	public static String trim(String s)
	   {
	     String sreturn="";
	     if (s!=null)
	     {
	       sreturn=s.trim();
	     }
	     return sreturn;
	   }
	/**
	 * @String 去除字符串的前后空格
	 * */
	public static String getArrayToString(String[] array, String boxOff){
		StringBuffer str = new StringBuffer();

		for(int i = 0; i < array.length; i++){
			// 最后一个不拼接 ,
			if((i + 1) == array.length){
				str.append(trim(array[i]));
			}else{
				str.append(trim(array[i])).append(boxOff);
			}
		}

		return str.toString();
	}
	/**
	 * @String 格式化数字
	 * @param 输出为美式
	 * */
	public static String convertNumber(String numberString){
		String val ="";		
		NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
		double number = Double.parseDouble(numberString);
		val = numberFormat.format(number);
		return val;
	}
	/**
	 * @String 格式化货币
	 * @param 输出为人民币
	 * */
	public static String convertCurrencyRMB(String numberString)
	{
		String val = "";	
		if("".equals(CommonTools.null2String(numberString))){
			numberString="0";
		}
		NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.PRC);
		double number = Double.parseDouble(numberString);
		val = currencyFormat.format(number);
		return val;
	}
	/**
	 * @String 格式化货币
	 * @param 输出为美元
	 * */
	public static String convertCurrencyUS(String numberString)
	{
		String val = "";		
		if("".equals(CommonTools.null2String(numberString))){
			numberString="0";
		}
		NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.US);
		double number = Double.parseDouble(numberString);
		val = currencyFormat.format(number);
		return val;
	}
	/**
	 * @String 格式化货币
	 * @param 输出为欧元
	 * */
	public static String convertCurrencyUK(String numberString)
	{
		String val = "";		
		if("".equals(CommonTools.null2String(numberString))){
			numberString="0";
		}
		NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.UK);
		double number = Double.parseDouble(numberString);
		val = currencyFormat.format(number);
		return val;
	}
	//四舍五入保留2位小数
	public static String getTwoDecimal(String number){
		java.text.DecimalFormat   df=new   java.text.DecimalFormat("#0.00"); 
		String val ="";
		if(number != null && !"".equals(number)){
			val = df.format(Double.parseDouble(number));
		}
		return val;
	}
}
